package com.whitedust.top30;

import com.whitedust.structure.ListNode;
import com.whitedust.structure.TreeNode;

import java.util.List;

/**
 * @author A
 * @since 2025/11/3 19:14
 */

public class Top22 {
    public boolean hasCycle(ListNode head) {
        //环形链表，快慢指针，两倍长度，当快指针为null则表示到头了
        if (head == null) return false;
        ListNode slow = head;
        ListNode fast = head;
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
            if (slow == fast) return true;
        }
        return false;
    }
}
